package com.zoo.diannaopeijian.service.impl;

import com.zoo.diannaopeijian.common.page.Page;
import com.zoo.diannaopeijian.common.util.CheckUtil;
import com.zoo.diannaopeijian.domain.PurchaseRecord;
import com.zoo.diannaopeijian.mapper.PurchaseRecordMapper;
import com.zoo.diannaopeijian.service.PurchaseRecordService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * 进货记录服务实现类
 */
@Service
public class PurchaseRecordServiceImpl implements PurchaseRecordService {
    @Resource
    private PurchaseRecordMapper purchaseRecordMapper;

    @Override
    public boolean insertPurchaseRecord(PurchaseRecord purchaseRecord) {
        if (CheckUtil.allNullBeanCheck(purchaseRecord)) {
            return true;
        }
        return purchaseRecordMapper.insertSelective(purchaseRecord) == 1;
    }

    @Override
    public List<Map> getPurchaseRecord(Date from, Date to, String staffName) {
        return purchaseRecordMapper.selectPurchaseRecord(from, to, staffName);
    }

    @Override
    public List<Map> getPurchaseRecordWithPage(Date from, Date to, String staffName, Page page) {
        if (page != null) {
            page.onPage();
        }

        return getPurchaseRecord(from, to, staffName);
    }
}
